package com.yh.homestay.controller;

import com.yh.homestay.common.CapitalRoomResult;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.pojo.CapitalRoom;
import com.yh.homestay.service.CapitalRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName CapitalRoomController
 * @Description 房间Controller
 * @Author GCL
 * @Date 2020/1/2 9:07
 */
@RestController
@RequestMapping("/room")
public class CapitalRoomController {

    @Autowired
    private CapitalRoomService roomService;

    /**
     * @param
     * @Date: 2020/1/4 15:03
     * @Description: 展示房间信息列表
     * @return: com.yh.homestay.common.ResultMessage
     */
    @RequestMapping("/list")
    public HomeStayResult showCapitalRoom(Integer page, Integer limit, String roomName) {
        return roomService.showCapitalRoom(page,limit,roomName);
    }

    /**
     * @param roomId
     * @Date: 2020/1/4 15:14
     * @Description: 删除单条数据
     * @return: com.yh.homestay.common.CapitalRoomResult
     */
    @RequestMapping("/delete")
    public CapitalRoomResult deleteCapitalRoom(Integer roomId) {
        return roomService.deleteCapitalRoom(roomId);
    }

    /**
     * @param ids
     * @Date: 2020/1/4 15:14
     * @Description: 批量删除房间信息
     * @return: com.yh.homestay.common.CapitalRoomResult
     */
    @RequestMapping("/deleteBatch")
    public CapitalRoomResult deleteCapitalRoom(String ids) {
        return roomService.deleteCapitalRoom(ids);
    }

    /**
     * @param room
     * @Date: 2020/1/4 15:21
     * @Description: 添加房间信息
     * @return: com.yh.homestay.common.CapitalRoomResult
     */
    @RequestMapping("/add")
    public CapitalRoomResult addRoom(CapitalRoom room) {
        return roomService.insertCapitalRoom(room);
    }

    /**
     * @param id
     * @Date: 2020/1/4 17:17
     * @Description: 页面回显
     * @return: com.yh.homestay.pojo.CapitalRoom
     */
    @RequestMapping("/one/{id}")
    public CapitalRoomResult showOne(@PathVariable("id") Integer id) {
        return roomService.showOneCapitalRoom(id);
    }

    /**
    * @Date: 2020/1/5 14:31
    * @Description: 编辑后更新数据
    * @param room
    * @return: com.yh.homestay.common.CapitalRoomResult
    */
    @RequestMapping("/update")
    public CapitalRoomResult editRoom(CapitalRoom room) {
        return roomService.updateCapitalRoom(room);
    }

    /**
    * @Date: 2020/1/5 14:42
    * @Description: 模糊查询
    * @param roomName
    * @return: com.yh.homestay.common.CapitalRoomResult
    */
    @RequestMapping("/fuzzy")
    //GET http://localhost/room-list.html?start=&end=&roomName=1
    public CapitalRoomResult fuzzyQuery(String roomName){
        return roomService.showFuzzy(roomName);
    }

}
